﻿/* Copyright 2012 Sannel Software, L.L.C.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at

 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
using System;
using System.Collections.Generic;
using System.Text;

namespace Sannel.Calculate.Nodes
{
	/// <summary>
	/// Represents a variable.
	/// </summary>
	public class VariableNode : BaseNode
	{
		/// <summary>
		/// Always returns NodeType.Variable
		/// </summary>
		public override NodeType NodeType
		{
			get { return Nodes.NodeType.Variable; }
		}
		
		/// <summary>
		/// The name of the variable
		/// </summary>
		public String Name
		{
			get;
			protected set;
		}

		/// <summary>
		/// Constructs a new node VariableNode with the given variable name
		/// </summary>
		/// <param name="name">The name of the variable. Name must not be null empty or all white space.</param>
		public VariableNode(String name)
		{
			if (name == null)
			{
				throw new ArgumentNullException("name");
			}

			if (StringHelpers.IsNullOrWhitespace(name))
			{
				throw new ExpressionParseException(Messages.VariableNameMustNotBeNullOrEmpty);
			}

			Name = name.Trim();
		}

		/// <summary>
		/// Creates a copy of this node but does not copy any of the links.
		/// </summary>
		/// <returns>A copy of this node</returns>
		public override BaseNode Copy()
		{
			return new VariableNode(Name);
		}
	}
}
